package com.ruoyi.lab.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lab.domain.LabProcurement;
import com.ruoyi.lab.service.ILabProcurementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购Controller
 * 
 * @author mojar
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/lab/procurement")
public class LabProcurementController extends BaseController
{
    @Autowired
    private ILabProcurementService labProcurementService;

    /**
     * 查询采购列表
     */
    @PreAuthorize("@ss.hasPermi('lab:procurement:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabProcurement labProcurement)
    {
        startPage();
        List<LabProcurement> list = labProcurementService.queryList(labProcurement);
        return getDataTable(list);
    }

    /**
     * 导出采购列表
     */
    @PreAuthorize("@ss.hasPermi('lab:procurement:export')")
    @Log(title = "采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabProcurement labProcurement)
    {
        List<LabProcurement> list = labProcurementService.queryList(labProcurement);
        ExcelUtil<LabProcurement> util = new ExcelUtil<>(LabProcurement.class);
        util.exportExcel(response, list, "采购数据");
    }

    /**
     * 获取采购详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:procurement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(labProcurementService.getById(id));
    }

    /**
     * 新增采购
     */
    @PreAuthorize("@ss.hasPermi('lab:procurement:add')")
    @Log(title = "采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabProcurement labProcurement)
    {
        return toAjax(labProcurementService.save(labProcurement));
    }

    /**
     * 修改采购
     */
    @PreAuthorize("@ss.hasPermi('lab:procurement:edit')")
    @Log(title = "采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabProcurement labProcurement)
    {
        return toAjax(labProcurementService.updateById(labProcurement));
    }

    /**
     * 删除采购
     */
    @PreAuthorize("@ss.hasPermi('lab:procurement:remove')")
    @Log(title = "采购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(labProcurementService.removeBatchByIds(ids));
    }
}
